package com.maiji.cloud.controller;

import java.util.List;

import com.maiji.cloud.entities.login.AdviceFeedbackEntity;
import com.maiji.cloud.request.ReqMetaData;
import com.maiji.cloud.response.BaseMetaResDto;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.login.AdviceFeedbackListReqData;
import com.maiji.cloud.request.login.AdviceFeedbackReqData;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.Status;
import com.maiji.cloud.response.login.AdviceFeedbackListResData;
import com.maiji.cloud.service.AdviceFeedbackService;

/**
 * 意见反馈
 * Description:  
 * @author zhanglr  
 * @date 2019年11月8日
 */
@RestController
@RequestMapping("/feedback/")
public class AdviceFeedbackController {
	private static final Logger logger = LoggerFactory.getLogger(AdviceFeedbackController.class);
	
	@Autowired
	private AdviceFeedbackService adviceFeedbackService;
	
	/**
	 * 用户反馈
	 * @param param
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("addAdviceFeedback")
	public BaseResDto addAdviceFeedback(@RequestBody BaseDataReqDto<AdviceFeedbackReqData> param,@RequestHeader("maijiToken")String maijiToken){
		logger.info("AdviceFeedbackController.addAdviceFeedback,param is {},maijiToken is {}",JSON.toJSONString(param),maijiToken);
		
		if(StringUtils.isBlank(param.getData().getContent()) && (param.getData().getImgIds() == null || param.getData().getImgIds().size() == 0)) return BaseResDto.baseResDto(Status.ERROR, "参数为空");
		
		return adviceFeedbackService.addAdviceFeedback(param,maijiToken);
		
	}
	
	/**
	 * 意见反馈列表（分页）
	 * @param param
	 * @return
	 */
	@PostMapping("getAdviceFeedbackList")
	public BaseDataResDto<List<AdviceFeedbackListResData>>  getAdviceFeedbackList(@RequestBody BaseDataReqDto<AdviceFeedbackListReqData> param){
		logger.info("AdviceFeedbackController.getAdviceFeedbackList,param is {}",JSON.toJSONString(param));
		return adviceFeedbackService.getAdviceFeedbackList(param);
	}

	/**
	 * 获取用户反馈列表
	 */
	@PostMapping("findAllAdviceFeedbacks")
	public BaseMetaResDto<List<AdviceFeedbackEntity>> findAllAdviceFeedbacks(@RequestBody BaseDataReqDto<AdviceFeedbackEntity> baseDataReqDto){
        AdviceFeedbackEntity adviceFeedback = baseDataReqDto.getData();
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return adviceFeedbackService.findAllAdviceFeedbacks(adviceFeedback, metaData);
	}

	/**
	 * 客服回复用户反馈
	 */
	@PostMapping("replyAdviceFeedback")
	public BaseResDto replyAdviceFeedback(@RequestBody BaseDataReqDto<AdviceFeedbackEntity> baseDataReqDto){
        AdviceFeedbackEntity adviceFeedback = baseDataReqDto.getData();
        return adviceFeedbackService.replyAdviceFeedback(adviceFeedback);
	}
	
	
}
